//
//   PriorityQueue.swift
//  Chapter3LinkedList
//
//  Created by TRS-Mobile on 2021/9/2.
//

import Foundation

struct PriorityQueue<E: Equatable>: Queue {
    
    typealias Element = E
    private var heap: Heap<E>
    
    init(sort: @escaping (E, E) -> Bool, elements: [E] = []) {
        self.heap = Heap(sort: sort, elements: elements)
    }
    
    @discardableResult
    mutating func enqueue(_ e: E) -> Bool {
        heap.insert(e)
        return true
    }
    
    @discardableResult
    mutating func dequeue() -> E? {
        return heap.remove()
    }
    
    var isEmpty: Bool {
        return heap.isEmpty
    }
    
    var peek: E? {
        return heap.peek()
    }
    
    
    
    
}
